<?php

namespace app\api\controller;

use think\Controller;
use app\api\model\Address as AddressModel;

class Address extends Base
{
    //检查用户Token 前置操作
    protected $beforeActionList = ['checkToken'];

    //地址列表
    public function list()
    {
        $res['status'] = 0;
        $res['data'] = AddressModel::getByUid($this->userId);
        return self::apiResp($res);
    }

    //添加地址
    public function save()
    {
        $data = input('post.');
        $data['user_id'] = $this->userId;
        $res = (new AddressModel())->addOrEdit($data);
        return self::apiResp($res);
    }

    //删除地址
    public function delete()
    {
        $id = input('post.id');
        $res = AddressModel::deleteById($id,$this->userId);
        return self::apiResp($res);
    }
}
